class Iterator {

    constructor(index = 0, data = [1, 2, 3, 4, 5]) {
        this.index = index
        this.data = data
        this.length = data.length
    }

    next() {
        if (!this.hasNext()) {
            return null
        }
        let element = this.data[this.index]
        this.index = this.index + 2
        return element
    }

    hasNext() {
        return this.index < this.length
    }

    rewind() {
        this.index = 0
    }

    current() {
        return data[this.index]
    }
}

let iterator = new Iterator(0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
while (iterator.hasNext()) {
    console.log(iterator.next())
}